package com.example.leetdemo.process;

import com.alibaba.fastjson.JSONObject;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class Solution318 {

    public int maxProduct(String[] words) {
        Integer product = 0;
        Arrays.sort(words, Comparator.comparing(String::length));

        for (int i = 0; i < words.length; i++) {
            for (int j = i + 1; j < words.length; j++) {
                int result = calculatorLength(words[i], words[j]);
                if (result > 0 ) {
                    product = Math.max(product, result);
                    j = words.length;
                }
            }
        }

        return product;
    }

    private int calculatorLength(String a, String b) {
//        if (a.length() + b.length() > 26) {
//            return -1;
//        }
        // 已知 a.length >= b.length
        for (int i = 0; i < b.length(); i++) {
            if (a.contains(b.charAt(i) + "")) {
                return -1;
            }
        }
        return a.length() * b.length();
    }

    public static void main(String[] args) {
        Solution318 solution318 = new Solution318();
//        System.err.println(solution318.maxProduct(new String[] {"aab", "bb", "ca"}));
        BigDecimal test = BigDecimal.valueOf(10).subtract(BigDecimal.valueOf(7)).divide(BigDecimal.valueOf(2), 4, RoundingMode.HALF_UP);
        System.err.println(test);

        List<BigDecimal> list = new ArrayList<>();
        list.add(BigDecimal.valueOf(100));
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("test", list);
        List<BigDecimal> list1 = jsonObject.getObject("test", ArrayList.class);
        list.forEach(System.out::println);

        System.err.println("success".equals(null));
    }

}
